<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            background: url(images/tao.jpeg);
            background-position: center;
        }
        
        div {
            margin: 300px auto;
            text-align: center;
        }
        
        p {
            font-size: 30px;
            color: #fff;
        }
        
        span {
            display: inline-block;
            width: 80px;
            height: 80px;
            background-color: rgb(250, 118, 118);
            font-size: 20px;
            color: #fff;
            text-align: center;
            line-height: 80px;
            border-radius: 50%;
        }
    </style>
</head>

<body>
    <div>
        <p>距离见到宝贝还剩</p>
        <span class="day"></span>
        <span class="hour"></span>
        <span class="minute"></span>
        <span class="second"></span>
    </div>
    <script>
        var day = document.querySelector('.day')
        var hour = document.querySelector('.hour')
        var minute = document.querySelector('.minute')
        var second = document.querySelector('.second')
        var inputTime = +new Date('2020-12-31 18:00:00');
        countDown();
        setInterval(countDown, 1000);

        function countDown() {
            var nowTime = +new Date();

            var times = (inputTime - nowTime) / 1000;
            var d = parseInt(times / 60 / 60 / 24)
            d = d < 10 ? '0' + d : d;
            day.innerHTML = d + '天'
            var h = parseInt(times / 60 / 60 % 24)
            h = h < 10 ? '0' + h : h;
            hour.innerHTML = h + '时'
            var m = parseInt(times / 60 % 60)
            m = m < 10 ? '0' + m : m;
            minute.innerHTML = m + '分'
            var s = parseInt(times % 60)
            s = s < 10 ? '0' + s : s;
            second.innerHTML = s + '秒'
        }
    </script>
</body>

</html>